<?php
/**
 * 时间展示函数（为了批量操作中时间显示）
 * $cycle ,$date ,$time
 */
function showTimes($cycle ,$date ,$time){
	$weekarr = array(
		'Mon'=>'星期一',
		'Tue'=>'星期二',
		'Wed'=>'星期三',
		'Thu'=>'星期四',
		'Fri'=>'星期五',
		'Sat'=>'星期六',
		'Sun'=>'星期天'	
	);
	switch($cycle){
		case 'Monthly':
			echo '每月'.$date.'号:'.$time ;
			break ;
		case 'Weekly':
			$week = explode('|',$date);
			$rundate = '';
			foreach ($week as $key){
				$rundate .=$weekarr[$key].',';
			}
			echo '每周'.trim($rundate ,',').':'.$time ;
			break ;
		case 'Every-day':
			echo '每天:'.$time ;
			break ;
		case 'One-time':
			echo $time ;
			break ;	
	}
}

/**
 * 请求接口
 */

function curl_request($method ,$params ,$url){
	$ch = curl_init();
	$timeout = 10;
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	switch($method){
		case 'DELETE': 
            curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($params)); 
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, self::DELETE); 
            break; 
        case 'POST': 
            curl_setopt($ch, CURLOPT_URL, $url); 
            curl_setopt($ch, CURLOPT_POST, true); 
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 
			
            break; 
        case 'GET': 
            curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($params)); 
            break; 
	}
	$file_contents = curl_exec($ch);//获得返回值
	curl_close($ch);
	return $file_contents;
}


/**
 * 获取操作系统
 */
function getSystem(){  
    $sys = $_SERVER['HTTP_USER_AGENT'];  
    if(stripos($sys, "NT 6.1"))  
       $os = "Windows 7";  
    elseif(stripos($sys, "NT 6.0"))  
       $os = "Windows Vista";  
    elseif(stripos($sys, "NT 5.1"))  
       $os = "Windows XP";  
    elseif(stripos($sys, "NT 5.2"))  
       $os = "Windows Server 2003";  
    elseif(stripos($sys, "NT 5"))  
       $os = "Windows 2000";  
    elseif(stripos($sys, "NT 4.9"))  
       $os = "Windows ME";  
    elseif(stripos($sys, "NT 4"))  
       $os = "Windows NT 4.0";  
    elseif(stripos($sys, "98"))  
       $os = "Windows 98";  
    elseif(stripos($sys, "95"))  
       $os = "Windows 95";  
    elseif(stripos($sys, "Mac"))  
       $os = "Mac";  
    elseif(stripos($sys, "Linux"))  
       $os = "Linux";  
    elseif(stripos($sys, "Unix"))  
       $os = "Unix";  
    elseif(stripos($sys, "FreeBSD"))  
       $os = "FreeBSD";  
    elseif(stripos($sys, "SunOS"))  
       $os = "SunOS";  
    elseif(stripos($sys, "BeOS"))  
       $os = "BeOS";  
    elseif(stripos($sys, "OS/2"))  
       $os = "OS/2";  
    elseif(stripos($sys, "PC"))  
       $os = "Macintosh";  
    elseif(stripos($sys, "AIX"))  
       $os = "AIX";  
    else  
       $os = "未知操作系统";   
    return $os;  
} 

/**
 * 获取服务器软件
 */
function getServerSoft(){
	$soft = $_SERVER['SERVER_SOFTWARE'];
	$soft = explode('/',$soft);
	return $soft[0];	
}

/**
 * 获取随机值 SIMPLE or COMPLEX
 */
function randomkey($style = 'SIMPLE'){
	$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
	$list = explode(",", $str);
	$cmax = count($list) - 1;
	$key = '';
	for ( $i=0; $i < 10; $i++ ){
	    $randnum = mt_rand(0, $cmax);
	    $key .= $list[$randnum]; 
	}

	if ($style == 'SIMPLE') {
		return date('Y/m/d/H/i/s/') . $key;
	} else {
		$key .=sha1(date('YmdHis'));
		return base64_encode($key);
	}
}

?>
